package cn.iocoder.yudao.framework.weixin;


import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpTpDepart;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceImpl;

import java.util.List;


public class WxCpServiceSanFangTest {
    /**
     * corpid:ww00b36ed5acf38dc9
     * AgentId：1000088
     * Secret：Q3wRLD9KRPMYAFpQ7EChakoRe5lWE9lt45kjfRN3sMk
     * @param args
     * @throws WxErrorException
     *
     * 请求地址： https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=1000088&corpsecret=Q3wRLD9KRPMYAFpQ7EChakoRe5lWE9lt45kjfRN3sMk
     */

    //服务商的
    static String providercorpid = "ww00b36ed5acf38dc9";
    static String providerSecret = "gFjBpLXZcwSYCdI6hq2bMxBnlw-v1Xkk0WbTJJVhAAZ1soHfXgF0Owpi-yKl9AgD";

    //模板的
    static String Token = "TPJ4Fdrpasg4R";
    static String encodingAESKey = "msJgW0YBhnDkKQnGz8gtdSFnSarTSIxztBXWxicDPBR";
    //模板ID：dk83899bb2c060ce44
    //模板Secret：iK3sD1n5ovlRTDOl424mu5uGKO_VgXS5oa7V2Yf9UMA
    static String corpid = "dk83899bb2c060ce44";
    static String secret = "iK3sD1n5ovlRTDOl424mu5uGKO_VgXS5oa7V2Yf9UMA";
    public static void main(String[] args) throws WxErrorException {
        //getSuiteAccessToken();
        //simplelist();
        simplelist();
    }


    /**
     * 7emnpxXKf4rgv0GCti_2w01y0C761YYO-iAD_Jza3kNA58BKFBDmOGXer2c1NYXh
     * 获取部门id列表
     * @throws WxErrorException
     */
    public static void simplelist() throws WxErrorException {
        WxCpServiceImpl baseWxCpService = new WxCpServiceImpl();
        WxCpDefaultConfigImpl wxCpDefaultConfig = new WxCpDefaultConfigImpl();
        wxCpDefaultConfig.setCorpId("wp-719DgAAy9Y7e5xDMmLf48VBLM1jUg");
        wxCpDefaultConfig.setCorpSecret("C37Utx4cYlWHl04JP_g0Y891wW17N9AuOB_M8qKGtM4");
       wxCpDefaultConfig.setAccessToken("EYry_YMv-DyXqGFKZXvigWuv3snFDXZL0fDPrVoCEa31z4vErpTb1bnqhfLqbuXAtBjxsB1YwA0xgc6J68HVFPnYq4XO_7Vhg-aVaPtP9xnJGencOhWgC0_hGX6IV94dIrkNdi_x-4_79JjbI1Dv5GntBIlESmvizMkkCMdJzzZ38SeG5UPSSq8n_qo6FGjL2bksp6Sh-6e7Pp6PQuXkYQ");

//        wxCpDefaultConfig.setSuiteTicket("Iw8BmGATuXLo5G4eHmMmpxMFrIuwKRA4No7j2THNT0TQc95dBjsxvQ7TJsnUfVFn");
//        wxCpDefaultConfig.setSuiteTicketExpiresTime();
        baseWxCpService.setWxCpConfigStorage(wxCpDefaultConfig);



        List<WxCpDepart> list = baseWxCpService.getDepartmentService().list(null);
        list.forEach(System.out::println);

    }

    public static void getSuiteAccessToken() throws WxErrorException {
        WxCpTpServiceImpl baseWxCpService = new WxCpTpServiceImpl();
        WxCpTpDefaultConfigImpl wxCpTpConfigStorage = new WxCpTpDefaultConfigImpl();
        wxCpTpConfigStorage.setSuiteId(corpid);
        wxCpTpConfigStorage.setSuiteSecret(secret);


//        wxCpTpConfigStorage.setSuiteTicket("Iw8BmGATuXLo5G4eHmMmpxMFrIuwKRA4No7j2THNT0TQc95dBjsxvQ7TJsnUfVFn");
//        wxCpTpConfigStorage.setSuiteTicketExpiresTime();
        baseWxCpService.setWxCpTpConfigStorage(wxCpTpConfigStorage);
        baseWxCpService.setSuiteTicket("Iw8BmGATuXLo5G4eHmMmp2jq87qe_UZwx2m6uFVHTcNR1wnRpTngXxi6ULt_Lp4t");
        String suiteAccessToken = baseWxCpService.getSuiteAccessToken();
        System.out.println(suiteAccessToken);

    }

}
